package com.sc.servlet.admin.user;

import com.alibaba.fastjson.JSONObject;
import com.sc.pojo.Field;
import com.sc.pojo.User;
import com.sc.services.FieldServices;
import com.sc.services.UserServices;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

/**
 * @description: 管理员修改用户信息
 * @author: sc
 * @create: 2023-01-05 20:39
 **/
@WebServlet("/updateUser")
public class updateUserServlet extends HttpServlet {

    private UserServices userServices = new UserServices();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        BufferedReader reader = request.getReader();
        String readLine = reader.readLine();
        JSONObject jsonObject = JSONObject.parseObject(readLine);
        String res=null;

        User updateuser = new User();
        updateuser.setUserid(jsonObject.getString("userid"));
        updateuser.setPassword(jsonObject.getString("password"));
        updateuser.setUsername(jsonObject.getString("username"));
        updateuser.setSex(jsonObject.getString("sex"));
        updateuser.setPhone(jsonObject.getString("phone"));

        userServices.updateUserMes(updateuser);



        res ="update_suc";
        response.setContentType("text/json;charset=utf-8");
        response.getWriter().write(res);



    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}